package org.qing.cloud.common.security.util;

import org.jasypt.util.text.BasicTextEncryptor;

public class JasyptPasswordUtils {

	public static String encrypt(String password, String plaintext) {
		BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
		// 加密所需的salt(盐)
		textEncryptor.setPassword(password);
		return textEncryptor.encrypt(plaintext);
	}

	public static String decrypt(String password, String cipher) {
		BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
		// 加密所需的salt(盐)
		textEncryptor.setPassword(password);
		return textEncryptor.decrypt(cipher);
	}

	public static void main(String[] args) {
//		String c1 = encrypt("qos", "qos");
//		String c2 = encrypt("qos", "qos");
//		System.out.println("c1:" + c1);
//		System.out.println("c2:" + c2);
//		String d1 = decrypt("qos", c1);
//		String d2 = decrypt("qos", c2);
//		System.out.println("d1:" + d1);
//		System.out.println("d2:" + d2);
	}
}
